"""
If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p = 1000, has the most solutions?
"""
i = 20
for s in range(12, i, 2):
  res = [(x,y,s-x-y) for x in range(1,s) for y in range(1,x) if x**2 + y**2 == (s-x-y)**2]
  if len(res) >= 3:
	  print s, res

import itertools, math
N = 10000
nsol = [0]*N
for a in xrange(1, N-N/2):
    for b in itertools.count(a+1):
        c_squared = a*a + b*b
        c = int( math.sqrt( c_squared))
        p = a + b + c
        if not p < N: break
        if c*c == c_squared:
            nsol[p] += 1
print nsol.index( max( nsol))

